﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SAP.Middleware.Connector;
using DataTier;

namespace BusinessTier
{
    public class EmpCtr
    {
        private SapConnectionCtr _sapConnecttionCtr = SapConnectionCtr.Instance;
        private static EmpCtr instance = null;

        public static EmpCtr Instance
        {
            get
            {
                if (instance == null)
                {
                    instance = new EmpCtr();
                }
                return instance;
            }
        }


        public List<Employee> GetAllEmployees(string firstname, string lastname)
        {
            IRfcTable irfcTable = _sapConnecttionCtr.GetEmployees(firstname, lastname);

            List<Employee> empList = BuildEmployees(irfcTable);

            return empList;
        }

        private List<Employee> BuildEmployees(IRfcTable irfcTable)
        {
            List<Employee> empList = new List<Employee>();

            for (int i = 0; i <= irfcTable.RowCount - 1; i++)
            {
                Employee emp = new Employee();

                emp._firstName = irfcTable[i].GetString("FSTNAME_M");
                emp._lastName = irfcTable[i].GetString("LASTNAME_M");
                emp._empNr = irfcTable[i].GetString("PERNO");

                empList.Add(emp);
            }

            return empList;

            

        }

    }
}

    
